import { _decorator, Component, instantiate, Node, Prefab, UITransform } from 'cc';
const { ccclass, property } = _decorator;
import { CardsData } from "./CardsData";
import { CardItemPrefab } from "./CardItemPrefab";

@ccclass('Game')
export class Game extends Component {
    @property(Prefab)
    cardPrefab: Prefab = null;
    
    @property(Node)
    handCardsParent: Node = null;

    start() {
        console.log("test===")
        this.initCards();
    }

    initCards() {
        console.log("1222222222222");
        this.handCardsParent.removeAllChildren();

        let ret = CardsData.ins.getCards();
        ret.forEach(val => {

            // 创建牌预制体
            let cardNode = instantiate(this.cardPrefab);
            console.log("------------cardNode--------", cardNode);
            
            let CardItem = cardNode.getComponent(CardItemPrefab);
            // cardNode.getComponent(UITransform).setContentSize(150, 150 * 2);
            this.handCardsParent.addChild(cardNode);
            CardItem.setData(val);


        });
        console.log("ret: ", ret);
    }

    update(deltaTime: number) {
        
    }
}


